package com.bruce.hmily_provider_usercoupon.controller;

import com.bruce.hmily_entity.UserCoupon;
import com.bruce.hmily_provider_usercoupon.service.UserCouponService;
import org.dromara.hmily.core.bootstrap.HmilyTransactionBootstrap;
import org.dromara.hmily.core.helper.SpringBeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 类注释
 *
 * @author Bruce
 * @date 2021/3/19 5:45 PM
 */
@RestController
@RequestMapping("/usercoupon")
public class UserCouponController {
    @Autowired
    private UserCouponService userCouponService;

    //http://localhost:8802/usercoupon/update?userId=1&userCouponId=0&couponMoney=10
    @GetMapping(value = "/update")
    public UserCoupon update(long userId, long userCouponId, double couponMoney) {
        UserCoupon userCoupon = userCouponService.findByUserCouponId(userCouponId);
        if(userCoupon == null){
            userCoupon = new UserCoupon();
        }
        userCoupon.setUserId(userId);
        userCoupon.setCouponMoney(couponMoney);

        return userCouponService.save(userCoupon);
    }

    //http://localhost:8802/usercoupon/findByUserCouponId?id=1
    @GetMapping(value = "/findByUserCouponId")
    public UserCoupon findByUserCouponId(long id) {
        return userCouponService.findByUserCouponId(id);
    }

}
